#include<bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define LL long long
#define db double
using namespace std; 
string s;
map <string,int> a;
bool check()
{
	int now=0,len=0,flag=1,cnt=0;
	int tot1=0,tot2=0,l=s.length();
	for(int j=0;j<l;j++)
	{
		if('0'<=s[j]&&s[j]<='9'){
			if(now>65535)continue;
			len++;
			now*=10;
			now+=s[j]-'0';
			continue;
		}
		if(len||now){
			if(now>255&&!tot2){flag=0;break;}
			int w=0;
			do w++,now/=10; while(now);
			if(w!=len){flag=0;break;}
			now=0,len=0;cnt++; 
		}
		if(s[j]=='.'&&tot1>2){flag=0;break;}
		if(s[j]==':'&&(tot1!=3||tot2>0)){flag=0;break;}
		if(s[j]=='.')tot1++;if(s[j]==':')tot2++;
	}
	if(len||now){
		if(now>65535&&tot2)flag=0;
		int w=0;
		do w++,now/=10; while(now);
		if(w!=len)flag=0;
		now=0,len=0;cnt++;
	}
	else flag=0;
	if(cnt<5)flag=0; 
	if(tot1!=3||tot2!=1)flag=0;
	if(flag)return 1;
	else return 0;
}
int main(){
	fre(network);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>s;
		if(s=="Client")
		{
			cin>>s;
			if(!check())puts("ERR");
			else if(!a[s])puts("FAIL");
			else printf("%d\n",a[s]); 
		}
		else{
			cin>>s;
			if(a[s]){puts("FAIL");continue;}
			if(check()) puts("OK"),a[s]=i;
			else puts("ERR");
		}
	}
	return 0;
}

